﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace RightClickExtension
{
    class Helper
    {
        /// <summary>
        /// Writes to error log.
        /// </summary>
        /// <param name="ex">The ex.</param>
        /// <param name="message">The message.</param>
        public static void WriteToErrorLog(Exception ex, string message)
        {
            string logLocation = Path.Combine(Application.StartupPath, "Errorlog.txt");
            if (!File.Exists(logLocation))
                File.Create(logLocation);
            using (StreamWriter sw = File.AppendText(logLocation))
            {
                sw.WriteLine(message);
                sw.WriteLine(ex.ToString());
                if (ex.StackTrace != null)
                    sw.WriteLine(ex.StackTrace.ToString());
            }
        }

        /// <summary>
        /// Writes the action to log.
        /// </summary>
        /// <param name="actionText">The action text.</param>
        public static void WriteActionToLog(string actionText)
        {
            string logLocation = Path.Combine(Application.StartupPath, "Log.txt");
            if (!File.Exists(logLocation))
                File.Create(logLocation);
            using (StreamWriter sw = File.AppendText(logLocation))
            {
                sw.WriteLine(actionText);
            }

        }

    }
}
